/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dataBasePlaylisted;

import controlPlaylisted.ControlUserCommand;
import Response.ResponseUser;
import Request.RequestUser;
import dataPlaylisted.User;
import dataPlaylisted.UserSerializable;

import java.beans.XMLDecoder;

import java.io.FileInputStream;
import java.io.ObjectInputStream;

import java.io.FileNotFoundException;
import java.io.IOException;


import java.util.ArrayList;
/**
 *
 * @author Administrador
 */
public class getUserListCommand implements ControlUserCommand {

     

     public getUserListCommand() throws FileNotFoundException, IOException, ClassNotFoundException{
       
     }

//    public void execute(RequestUser _req, ResponseUser _resp) throws ClassNotFoundException {
//
//        UserSerializable ser_user;
//        ser_user = UserSerializable.getInstance();
//        try{
//            ser_user = (UserSerializable)m_in.readObject();
//            m_in.close();
//        }
//        catch(IOException e){
//        }
//
//        ArrayList<User> list = null;
//        list =  ser_user.getUserList();
//        _resp.setObjectList(list);
//    }

    public void execute(RequestUser _req, ResponseUser _resp) throws ClassNotFoundException {

        String file_name = "UserModel.xml";
        FileInputStream m_fis = null;
        ObjectInputStream m_in = null;
        XMLDecoder m_xdec;

        try{
            m_fis = new FileInputStream(file_name);
        }catch(IOException e){
        }

//        try{
//            m_in = new ObjectInputStream(m_fis);
//        }catch(IOException e){
//        }

        m_xdec = new XMLDecoder(m_fis);

        ArrayList<User> list = null;

        list = new ArrayList<User>();

        try {
            list = (ArrayList<User>) m_xdec.readObject();
        } catch (Exception e){
        }

        if (list == null)
            list = new ArrayList<User>();

        _resp.setObjectList(list);
    }

}
